<?php
require_once ('dbconfig.php');
require_once ('igb.php');
IGBRequireTrust ();
?>
<html>
<head>
<title>Corporate Ore Payout Calculator</title>
</head>
<body>
<?php
$dbh = mysql_connect ( DB_HOST, DB_USER, DB_PASS ) or die ( mysql_error () );
mysql_select_db ( DB_NAME );

echo "<h1>Corp Ore Payout Prices Page</h1> <br>";

$sql = "select * from OrePurchasePrice order by oreSeq";
$result = mysql_query ( $sql, $dbh ) or die ( mysql_error () );
$sql = "select * from OrePurchasePrice order by oreSeq";
$recCount = mysql_num_rows ( $result ); //$_POST [recCount];
$postVar = "recCount";
$recCountPassed = $_POST [$postVar];

//echo "record count from query is " . $recCount . "<br>";
//echo "record count from post variable is " .$recCountPassed ."<br>";
$count = 1;
$payOut = 0;
echo "<table border=1><tr><td><b>Ore</b></td><td align=\"right\"><b>Price</b></td><td><b>Qty</b></td><td><b>Value</b></td></tr>";
while ( $count <= $recCount ) {
	while ( $newArray = mysql_fetch_array ( $result ) ) {
		$oreName = $newArray ['oreName'];
		$orePrice = $newArray ['orePrice'];
		$nameVal = "ore" . $count;
		$oreQty = $_POST [$nameVal];
		if ($oreQty != "") {
			$oreValue = $oreQty * $orePrice;
			echo "<tr><td align=\"left\">$oreName</td>";
			echo "<td align=\"right\">$orePrice</td>";
			echo "<td>$oreQty</td><td align=\"right\">" . number_format ( $oreValue, 2 ) . "</td></tr>";
			$payOut += $oreValue;
		}
		$count ++;
	} //end of while loop
	$payOutValue = number_format ( $payOut, 2 );
	//printf("<tr><td></td><td></td><td></td><td>%.2f</td></tr>",$payOut);
	echo "<tr><td></td><td></td><td></td><td>$payOutValue</td></tr>";
	echo "</table>";
} //end loop


?>
</body>
</html>
